

interface Car {
    String driver();
}

class Benz implements Car {
    @Override
    public String driver() {
        return "开奔驰";
    }
}

class Audi implements Car {
    @Override
    public String driver() {
        return "开奥迪";
    }
}

class Bmw implements Car {
    @Override
    public String driver() {
        return "开宝马";
    }
}

class CarFactroy {
    public static Car getCar(String carName) {
        if ("Benz".equals(carName)) {
            return new Benz();
        } else if ("Audi".equals(carName)) {
            return new Audi();
        } else if ("Bmw".equals(carName)) {
            return new Bmw();
        }
        return null;
    }
}

// 小老板聘用一个司机来开不同车(奔驰/奥迪...)
public class SimpleFactoryTest {
    static public void test(String carName) {
        Car car = CarFactroy.getCar(carName);
        if (car == null) {
            System.out.println("老板还没有买" + carName + "这辆车!");
            return;
        }
        System.out.printf("老板叫司机%s去见客户!\n", car.driver());
    }

    static public void main(String [] args) {
        test("Benz");
        test("Audi");
        test("Bmw");
    }
}
